package com.mz.ieann.doplayer.audio

import android.content.Context
import android.content.res.AssetFileDescriptor
import android.view.ViewGroup
import com.mz.ieann.doplayer.audio.core.impl.media.MediaPlayerWrapper
import com.mz.ieann.doplayer.audio.core.listener.IAudioPlayer
import com.mz.ieann.doplayer.audio.listener.ProgressListener
import com.mz.ieann.doplayer.audio.widget.YouVisualizerView

/**
 * <p>------------------------------------------------------
 * <p>Copyright (C) 2020 wasu company, All rights reserved.
 * <p>------------------------------------------------------
 * <p>
 * <p>
 *
 * @author Created by zhangmz
 * @date on 2023/5/10
 */
object AudioHelper {

    const val TAG = "audio_player"

    private var iPlayer: IAudioPlayer? = null

    fun create(con: Context, assetFile: AssetFileDescriptor): AudioHelper{
        iPlayer = MediaPlayerWrapper(TAG, con).create(assetFile)
        return this
    }

    fun addListener(listener: ProgressListener?): AudioHelper{
        iPlayer?.addListener(listener)
        return this
    }

    fun addVisualizer(view: YouVisualizerView?): AudioHelper{
        iPlayer?.addVisualizer(view)
        return this
    }

    fun prepare(view: ViewGroup){
        iPlayer?.prepare(view)
    }

    fun updateProgress(progress: Int){
        iPlayer?.updateProgress(progress)
    }

    fun isPlaying(): Boolean{
        return iPlayer?.isPlaying()?: false
    }

    fun pause(){
        iPlayer?.pause()
    }

    fun stop(){
        iPlayer?.stop()
    }

    fun release(){
        iPlayer?.release()
    }

}